﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Domain.Models;
using IServices;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using ViewModel.EmployeeModel;
using ViewModel.Response;

namespace Management.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class EmployeeController : BaseController
    {
        private readonly IEmployeeService employeeService;

        public EmployeeController(IEmployeeService employeeService,ILogger logger):base(logger)
        {
            this.employeeService = employeeService;
        }

        /// <summary>
        /// 获取所有的员工信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ResponseModel<IEnumerable<EmployeeBase>> Get()
        {
            var result = new ResponseModel<IEnumerable<EmployeeBase>>
            {
                Data = this.employeeService.GetEmployees(),
                Status = ResponseStatus.OK
            };
            return result;
        }
        /// <summary>
        /// 获取员工详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public ResponseModel<Employee> GetEmployee(int id)
        {
            var result = new ResponseModel<Employee>
            {
                Data = this.employeeService.QueryById(id),
                Status = ResponseStatus.OK
            };
            return result;
        }
        /// <summary>
        /// 创建员工
        /// </summary>
        /// <param name="model">员工模型</param>
        /// <returns></returns>
        [HttpPost]
        public ResponseModel<string> AddEmployee([FromBody]CreateEmployeeModel model)
        {
            var result = new ResponseModel<string>();

            var createResult = this.employeeService.CreateEmployee(model);
            if (createResult > 0)
            {
                result.Data = createResult.ToString();
                result.Status = ResponseStatus.OK;
            }
            return result;
        }
    }
}